package com.bangbang.blog.controller;


import com.bangbang.blog.pojo.TbAdmin;
import com.bangbang.blog.service.impl.TbAdminServiceImpl;
import com.bangbang.configresult.Result;
import com.bangbang.configresult.ResultEnum;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 * 运营商表 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-08-13
 */
@RestController
@RequestMapping("/blog/tbAdmin")
public class TbAdminController {

    @Autowired
    private TbAdminServiceImpl tbAdminService;

    @Autowired
    private RedisTemplate redisTemplate;

    //新增
    @PostMapping
    @ApiOperation("运营商的新增方法")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tbAdmin",value = "运营商实体类",required = true,paramType = "body")
    })
    public Result insert(@RequestBody TbAdmin tbAdmin){
        Object o1 = redisTemplate.boundValueOps("f8d51ba6-fd96-4e59-9d9e-0a873eed2b9e").get();
        long l = Long.parseLong(o1.toString() + "");//用户id
        tbAdminService.insert(tbAdmin);
        return Result.buildResult(ResultEnum.SUCCESS);

    }

    //修改
    @PutMapping
    @ApiOperation("运营商修改方法")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tbAdmin",value = "运营商实体类",required = true,paramType = "body")
    })
    public Result update(@RequestBody TbAdmin tbAdmin){
        tbAdminService.updateById(tbAdmin);
        return Result.buildResult(ResultEnum.SUCCESS);
    }

    //删除
    @DeleteMapping
    @ApiOperation("运营商删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "adminId",value = "运营商id",required = true,paramType = "query")
    })
    public Result delete(@RequestParam(required = true)Long adminId){
        tbAdminService.delete(adminId);
        return Result.buildResult(ResultEnum.SUCCESS);
    }

    //查询
    @GetMapping
    @ApiOperation("运营商查询方法")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "admin",value = "运营商id",required = true,paramType = "query")
    })
    public Result select(@RequestParam(required = true)Long adminId){
        tbAdminService.select(adminId);
        return Result.buildResult(ResultEnum.SUCCESS);
    }
}

